/**   
 * @Title: LotteryUtils.java 
 * @Package com.esun.util 
 * @Description: (购彩工具类) 
 * @author City Jiangsy@500wan.com   
 * @date 2011-6-22 下午12:33:12  
 * copy right 深圳市易讯天空网络技术有限公司
 */
package com.esun.util;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import java.util.TreeSet;

import com.esun.util.log.EDebug;

/**
 * @ClassName: LotteryUtils
 * @Description: (购彩工具类)
 * @author City Jiangsy@500wan.com
 * @date 2011-6-22 下午12:33:12
 * 
 */
public class LotteryUtils {
	/***
	 * 选出不重复随机号码
	 * 
	 * @param i
	 *            随机号码个数
	 * @param max
	 *            随机号码最大值
	 * @author miko
	 */
	public static ArrayList<Integer> randomNum(int howMany, int max) {

		EDebug.o(LotteryUtils.class,
				"Doing random auto howMany [" + String.valueOf(howMany)
						+ "] max [" + String.valueOf(max) + "]");

		Random random = new Random();

		HashSet<Integer> randomArray = new HashSet<Integer>();

		ArrayList<Integer> intList = new ArrayList<Integer>();

		while (true) {
			int temp = random.nextInt(max + 1);
			if (temp != 0) {
				randomArray.add(temp);
			}
			if (randomArray.size() == howMany) {
				break;
			}
		}

		TreeSet<Integer> tree = new TreeSet<Integer>();
		tree.addAll(randomArray);

		Iterator<Integer> iterator = tree.iterator();

		while (iterator.hasNext()) {
			intList.add(iterator.next());
		}
		for (int i = 0; i < intList.size(); i++) {
			EDebug.o(Integer.toString(intList.get(i)));
		}
		return intList;
	}

	public static String getLotRest(String userRest, int buying) {

		double userRestTemp;

		userRestTemp = Double.parseDouble(userRest);

		EDebug.o(LotteryUtils.class, "input UserRest is : " + userRest);
		EDebug.o(LotteryUtils.class, "input buying is : " + buying);

		double doubelTemp = userRestTemp - buying;
		EDebug.o(LotteryUtils.class, "input userRestTemp - buying is : "
				+ String.valueOf(doubelTemp));
		DecimalFormat format = new DecimalFormat("0.00");
		format.setMaximumFractionDigits(3);
		String afterBet = format.format(doubelTemp);
		return afterBet;
		/*
		 * if (doubelTemp >= 0) { return afterBet + "元"; } else { return
		 * "不足以完成投注"; }
		 */
	}

	public static String getLotRestBottom(String userRest, int buying) {

		double userRestTemp;

		userRestTemp = Double.parseDouble(userRest);

		EDebug.o(LotteryUtils.class, "input UserRest is : " + userRest);
		EDebug.o(LotteryUtils.class, "input buying is : " + buying);

		double doubelTemp = userRestTemp - buying;
		EDebug.o(LotteryUtils.class, "input userRestTemp - buying is : "
				+ String.valueOf(doubelTemp));
		DecimalFormat format = new DecimalFormat("0.00");
		String afterBet = format.format(doubelTemp);
		return afterBet;
	}

}
